package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

class zue {
   private Workbook a;
   private zok b;
   private HashMap c;

   zue(zok var1) {
      this.b = var1;
      this.a = var1.a;
   }

   void a(zcfx var1) throws Exception {
      var1.b(true);
      this.c(var1);
      this.n(var1);
      this.d(var1);
      this.p(var1);
      this.o(var1);
      this.l(var1);
      this.k(var1);
      this.q(var1);
      this.r(var1);
      this.i(var1);
      this.j(var1);
      this.e(var1);
      this.f(var1);
      this.h(var1);
      this.m(var1);
      this.b(var1);
      this.g(var1);
      var1.b();
      var1.d();
      var1.e();
   }

   private void b(zcfx var1) throws Exception {
      WorkbookSettings var2 = this.a.getSettings();
      if (var2.p != 0) {
         var1.b("fileRecoveryPr");
         if (!var2.getAutoRecover()) {
            var1.a("autoRecover", "0");
         }

         if (var2.getCrashSave()) {
            var1.a("crashSave", "1");
         }

         if (var2.getDataExtractLoad()) {
            var1.a("dataExtractLoad", "1");
         }

         if (var2.getRepairLoad()) {
            var1.a("repairLoad", "1");
         }

         var1.b();
      }
   }

   private void c(zcfx var1) throws Exception {
      var1.b("workbook");
      if (zase.a) {
         var1.a("xmlns", zase.c);
      } else {
         var1.a("xmlns", zase.d);
      }

      var1.a("xmlns", "r", (String)null, "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
      if (this.a.b != null && this.a.b.i != null && this.a.b.i.h != null) {
         Iterator var2 = this.a.b.i.h.iterator();

         while(var2.hasNext()) {
            Object var3 = var2.next();
            znm var4 = (znm)var3;
            var1.a(var4.a, var4.b);
         }
      }

   }

   private void d(zcfx var1) throws Exception {
      if (this.a.getSettings().isWriteProtected()) {
         var1.b("fileSharing");
         if (this.a.getSettings().getRecommendReadOnly()) {
            var1.a("readOnlyRecommended", "1");
         }

         String var2 = this.a.getWorksheets().ac();
         if (var2 == null) {
            var2 = "Aspose";
         }

         var1.a("userName", var2);
         var1.a("reservationPassword", com.aspose.cells.a.c.zp.b(this.a.getSettings().g() & '\uffff'));
         var1.b();
      }

   }

   private void e(zcfx var1) throws Exception {
      SmartTagOptions var2 = this.a.getSettings().n();
      if (var2 != null) {
         var1.b("smartTagPr");
         var1.a("embed", var2.getEmbedSmartTags() ? "1" : "0");
         switch(var2.getShowType()) {
         case 1:
            var1.a("show", "noIndicator");
            break;
         case 2:
            var1.a("show", "none");
         }

         var1.b();
      }

   }

   private void f(zcfx var1) throws Exception {
      zbnl var2 = this.a.getWorksheets().ab();
      if (var2 != null && var2.getCount() != 0) {
         var1.b("smartTagTypes");

         for(int var3 = 0; var3 < var2.getCount(); ++var3) {
            zbnk var4 = var2.a(var3);
            var1.b("smartTagType");
            var1.a("namespaceUri", var4.a());
            var1.a("name", var4.b());
            if (var4.a != null) {
               var1.a("url", var4.a);
            }

            var1.b();
         }

         var1.b();
      }
   }

   private boolean a() {
      if (this.a.b != null && this.a.b.i != null) {
         this.c = this.a.b.i.j;
         if (this.c != null && this.c.size() > 0) {
            return true;
         }
      }

      zbmv var1 = this.a.getWorksheets().W();
      int var2 = var1.getCount();
      return var2 > 0;
   }

   private void a(zcfx var1, int var2) throws Exception {
      if (this.b.z != null) {
         String var3 = null;
         String var4 = null;
         String var5 = null;
         switch(var2) {
         case 1:
            var3 = "{BBE1A952-AA13-448e-AADC-164F8A28A991}";
            var4 = "x14";
            var5 = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main";
            break;
         case 2:
            var3 = "{46BE6895-7355-4a93-B00E-2C351335B9C9}";
            var5 = "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main";
            var4 = "x15";
         }

         ArrayList var6 = (ArrayList)this.b.z.get(var3);
         if (var6 != null && var6.size() != 0) {
            var1.b("ext");
            var1.a("uri", var3);
            var1.a("xmlns", var4, (String)null, var5);
            var1.a(var4, "slicerCaches", false);
            if (var2 == 2) {
               var4 = "x14";
               var1.a("xmlns", var4, (String)null, "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
            }

            Iterator var7 = var6.iterator();

            while(var7.hasNext()) {
               String var8 = (String)var7.next();
               var1.a(var4, "slicerCache", false);
               var1.a("r:id", var8);
               var1.b();
            }

            var1.b();
            var1.b();
         }
      }
   }

   private void g(zcfx var1) throws Exception {
      if (this.a()) {
         var1.b("extLst");
         this.a(var1, "{876F7934-8845-4945-9796-88D515C7AA90}");
         this.a(var1, 1);
         this.a(var1, "{79F54976-1DA5-4618-B147-4CDE4B953A38}");
         this.a(var1, "{841E416B-1EF1-43b6-AB56-02D37102CBD5}");
         this.a(var1, "{A2CB5862-8E78-49c6-8D9D-AF26E26ADB89}");
         this.a(var1, "{983426D0-5260-488c-9760-48F4B6AC55F4}");
         this.a(var1, 2);
         this.a(var1, "{D0CA8CA8-9F24-4464-BF8E-62219DCF47F9}");
         this.a(var1, "{140A7094-0E35-4892-8432-C4D2E57EDEB5}");
         this.a(var1, "{FCE2AD5D-F65C-4FA6-A056-5C36A1767C68}");
         var1.b();
      }
   }

   private void a(zcfx var1, String var2) throws Exception {
      if (this.c != null && this.c.get(var2) != null) {
         String var3 = (String)this.c.get(var2);
         var1.d(var3);
      }
   }

   private void h(zcfx var1) throws Exception {
      if (this.a.getWorksheets().f != null && this.a.getWorksheets().f.getCount() > 0) {
         var1.b("customWorkbookViews");

         for(int var2 = 0; var2 < this.a.getWorksheets().f.getCount(); ++var2) {
            znd var3 = this.a.getWorksheets().f.a(var2);
            var1.b("customWorkbookView");
            var1.a("name", var3.j);
            var1.a("guid", "{" + com.aspose.cells.b.a.zr.a(var3.b) + "}");
            var1.a("activeSheetId", zase.y(var3.a));
            var1.a("xWindow", zase.y(var3.c));
            var1.a("yWindow", zase.y(var3.d));
            var1.a("windowWidth", zase.y(var3.e));
            var1.a("windowHeight", zase.y(var3.f));
            var1.a("mergeInterval", zase.y(var3.i));
            if (var3.m()) {
               var1.a("personalView", "1");
            }

            if (var3.o()) {
               var1.a("maximized", "1");
            }

            if (var3.j()) {
               var1.a("autoUpdate", "1");
            }

            if (var3.k()) {
               var1.a("changesSavedWin", "1");
            }

            if (!var3.h()) {
               var1.a("includeHiddenRowCol", "0");
            }

            if (!var3.g()) {
               var1.a("includePrintSettings", "0");
            }

            if (var3.n()) {
               var1.a("minimized", "0");
            }

            if (var3.l()) {
               var1.a("onlySync", "1");
            }

            switch(var3.c()) {
            case 0:
               var1.a("showComments", "commIndAndComment");
               break;
            case 2:
               var1.a("showComments", "commNone");
            }

            if (!var3.a()) {
               var1.a("showFormulaBar", "0");
            }

            if (!var3.p()) {
               var1.a("showHorizontalScroll", "0");
            }

            if (!var3.d()) {
               var1.a("showVerticalScroll", "0");
            }

            switch(var3.f()) {
            case 0:
            default:
               break;
            case 1:
               var1.a("showObjects", "none");
               break;
            case 2:
               var1.a("showObjects", "placeholders");
            }

            if (!var3.e()) {
               var1.a("showSheetTabs", "0");
            }

            if (!var3.b()) {
               var1.a("showStatusbar", "0");
            }

            if (var3.h != 600) {
               var1.a("tabRatio", zase.y(var3.h));
            }

            var1.b();
         }

         var1.b();
      }

   }

   private void i(zcfx var1) throws Exception {
      if (this.b.w) {
         var1.b("calcPr");
         var1.a("calcId", "125725");
         var1.a("calcMode", zase.ao(2));
         var1.a("calcCompleted", "0");
         var1.a("calcOnSave", "0");
         var1.b();
      } else {
         var1.b("calcPr");
         if (!this.a.getSettings().getReCalculateOnOpen()) {
            var1.a("calcId", zase.y(this.a.getSettings().f));
         }

         if (this.a.getSettings().getCalcMode() != 0) {
            var1.a("calcMode", zase.ao(this.a.getSettings().getCalcMode()));
         } else if (this.a.getSettings().getReCalculateOnOpen()) {
            var1.a("fullCalcOnLoad", "1");
         }

         if (this.a.getSettings().getPrecisionAsDisplayed()) {
            var1.a("fullPrecision", "0");
         }

         if (this.a.getSettings().getCalcMode() == 2 && !this.a.getSettings().getRecalculateBeforeSave()) {
            var1.a("calcCompleted", "0");
            var1.a("calcOnSave", "0");
         }

         if (this.a.getSettings().getIteration()) {
            var1.a("iterate", "1");
            var1.a("iterateCount", zase.y(this.a.getSettings().getMaxIteration()));
            var1.a("iterateDelta", zase.b(this.a.getSettings().getMaxChange()));
         }

         if (this.a.getSettings().d()) {
            var1.a("refMode", "R1C1");
         }

         var1.b();
      }
   }

   private void j(zcfx var1) throws Exception {
      if (this.a.getWorksheets().getOleSize() != null) {
         var1.b("oleSize");
         var1.a("ref", zase.a((CellArea)this.a.getWorksheets().getOleSize()));
         var1.b();
      }

   }

   private void k(zcfx var1) throws Exception {
      var1.b("sheets");

      for(int var2 = 0; var2 < this.b.c.size(); ++var2) {
         zol var3 = (zol)this.b.c.get(var2);
         var1.b("sheet");
         var1.a("name", var3.a.getName());
         String var4 = zase.y(var3.a.l());
         var1.a("sheetId", var4);
         if (!var3.a.isVisible()) {
            String var5 = "hidden";
            if (var3.a.p()) {
               var5 = "veryHidden";
            }

            var1.a("state", var5);
         }

         var1.a("r:id", (String)null, var3.k);
         var1.b();
      }

      var1.b();
   }

   private void l(zcfx var1) throws Exception {
      var1.b("bookViews");
      var1.b("workbookView");
      if (this.a.getSettings().isHidden()) {
         var1.a("visibility", "hidden");
      }

      if (this.a.getSettings().isMinimized()) {
         var1.a("minimized", "1");
      }

      if (!this.a.getSettings().isHScrollBarVisible()) {
         var1.a("showHorizontalScroll", "0");
      }

      if (!this.a.getSettings().isVScrollBarVisible()) {
         var1.a("showVerticalScroll", "0");
      }

      if (!this.a.getSettings().getShowTabs()) {
         var1.a("showSheetTabs", "0");
      }

      var1.a("xWindow", zase.y(this.a.getSettings().q()));
      var1.a("yWindow", zase.y(this.a.getSettings().r()));
      var1.a("windowWidth", zase.y(this.a.getSettings().s()));
      var1.a("windowHeight", zase.y(this.a.getSettings().t()));
      if (this.a.getSettings().getSheetTabBarWidth() != 600) {
         var1.a("tabRatio", zase.y(this.a.getSettings().getSheetTabBarWidth()));
      }

      int var2;
      zol var3;
      if (this.a.getWorksheets().C() != 0) {
         for(var2 = 0; var2 < this.b.c.size(); ++var2) {
            var3 = (zol)this.b.c.get(var2);
            if (var3.a.m() == this.a.getWorksheets().C()) {
               var1.a("firstSheet", zase.y(var3.c - 1));
               break;
            }
         }
      }

      if (this.a.getWorksheets().getActiveSheetIndex() >= 0) {
         for(var2 = 0; var2 < this.b.c.size(); ++var2) {
            var3 = (zol)this.b.c.get(var2);
            if (var3.a.m() == this.a.getWorksheets().getActiveSheetIndex()) {
               var1.a("activeTab", zase.y(var3.c - 1));
            }
         }
      }

      var1.b();
      var1.b();
   }

   private void a(zcfx var1, String var2, String var3) throws Exception {
      var1.b("pivotCache");
      var1.a("cacheId", var2);
      var1.a("r:id", var3);
      var1.b();
   }

   private void m(zcfx var1) throws Exception {
      if (this.b.h != null) {
         var1.b("pivotCaches");
         ArrayList var2 = this.b.h;
         if (var2 != null) {
            Iterator var3 = var2.iterator();

            while(var3.hasNext()) {
               zqc var4 = (zqc)var3.next();
               this.a(var1, var4.c, var4.e);
            }
         }

         var1.b();
      }
   }

   private void n(zcfx var1) throws Exception {
      zpl var2 = this.a.getSettings().v();
      if (var2 == null) {
         String var3 = "<fileVersion appName=\"xl\" lastEdited=\"4\" lowestEdited=\"4\" rupBuild=\"9302\" />";
         var1.d(var3);
      } else {
         if (var2 != null) {
            var1.b("fileVersion");
            if (var2.a != null) {
               var1.a("appName", var2.a);
            }

            if (var2.b != null) {
               var1.a("lastEdited", var2.b);
            }

            if (var2.c != null) {
               var1.a("lowestEdited", var2.c);
            }

            if (var2.d != null) {
               var1.a("rupBuild", var2.d);
            }

            if (var2.e != null) {
               var1.a("codeName", var2.e);
            }

            var1.b();
         }

      }
   }

   private void o(zcfx var1) throws Exception {
      if (this.a.getWorksheets().P()) {
         var1.b("workbookProtection");
         zbvh var2 = this.a.getWorksheets().N();
         if (var2.c != null) {
            zavu var3 = var2.c;
            if (var3.a == null) {
               if (var3.a() != 0) {
                  var1.a("workbookPassword", com.aspose.cells.a.c.zp.d(var3.a()));
               }
            } else {
               var1.a("workbookAlgorithmName", var3.a);
               var1.a("workbookHashValue", com.aspose.cells.b.a.ze.a(var3.b));
               var1.a("workbookSaltValue", com.aspose.cells.b.a.ze.a(var3.c));
               var1.a("workbookSpinCount", zase.y(var3.d));
            }
         }

         if (var2.b) {
            var1.a("lockStructure", "1");
         }

         if (var2.a) {
            var1.a("lockWindows", "1");
         }

         var1.b();
      }
   }

   private void p(zcfx var1) throws Exception {
      String var2 = null;
      String var3 = this.a.getWorksheets().h();
      boolean var4 = false;
      if (this.a.b != null) {
         zpd var5 = this.a.b.i;
         var2 = var5.d;
         var4 = var5.e;
      }

      var1.b("workbookPr");
      if (this.a.getSettings().getDate1904()) {
         var1.a("date1904", "1");
      }

      switch(this.a.getSettings().getUpdateLinksType()) {
      case 1:
         var1.a("updateLinks", "never");
         break;
      case 2:
         var1.a("updateLinks", "always");
      }

      if (var3 != null) {
         var1.a("codeName", var3);
      }

      if (this.a.getSettings().getRemovePersonalInformation()) {
         var1.a("filterPrivacy", "1");
      }

      if (this.a.getSettings().getHidePivotFieldList()) {
         var1.a("hidePivotFieldList", "1");
      }

      if (this.a.getWorksheets().isRefreshAllConnections()) {
         var1.a("refreshAllConnections", "1");
      }

      if (var4) {
         var1.a("publishItems", "1");
      }

      if (var2 != null && !this.a.d) {
         var1.a("defaultThemeVersion", var2);
      }

      if (!this.a.getSettings().getAutoCompressPictures()) {
         var1.a("autoCompressPictures", "0");
      }

      var1.b();
   }

   private void q(zcfx var1) throws Exception {
      zbqf var2 = this.a.getWorksheets().v();
      if (this.b.t.size() != 0) {
         var1.b("externalReferences");

         for(int var3 = 0; var3 < var2.getCount(); ++var3) {
            zqe var4 = (zqe)this.b.t.get(var3);
            if (var4 != null) {
               var1.b("externalReference");
               var1.a("r:id", (String)null, var4.c);
               var1.b();
            }
         }

         var1.b();
      }
   }

   private void r(zcfx var1) throws Exception {
      var1.b("definedNames");
      Iterator var2 = this.a.getWorksheets().getNames().iterator();

      while(true) {
         Name var3;
         String var4;
         do {
            do {
               do {
                  do {
                     if (!var2.hasNext()) {
                        this.s(var1);
                        var1.b();
                        return;
                     }

                     var3 = (Name)var2.next();
                  } while(var3.n() == 1);

                  var4 = var3.getRefersTo();
               } while(var4 == null);
            } while(var4.length() <= 1);

            if (var4.charAt(0) == '=') {
               var4 = var4.substring(1);
            }

            if (var4.equals("{}")) {
               var4 = "#REF!";
            }
         } while(var3.n() == 0 && var4.startsWith("#REF!"));

         int var5 = -1;
         if (var3.getSheetIndex() != 0) {
            for(int var6 = 0; var6 < this.b.c.size(); ++var6) {
               zol var7 = (zol)this.b.c.get(var6);
               if (var3.getSheetIndex() - 1 == var7.a.m()) {
                  var5 = var7.c - 1;
                  break;
               }
            }
         }

         String var8 = var3.getText();
         if (var3.p() != 0) {
            switch(var3.p()) {
            case 6:
               var8 = "_xlnm.Print_Area";
               break;
            case 7:
               var8 = "_xlnm.Print_Titles";
               break;
            case 13:
               var8 = "_xlnm._FilterDatabase";
            }
         } else if (com.aspose.cells.b.a.zv.a(var8, "_FilterDatabase", true, com.aspose.cells.b.a.c.za.b()) == 0) {
            var8 = "_xlnm._FilterDatabase";
         } else if (com.aspose.cells.b.a.zv.a(var8, "Print_Area", true, com.aspose.cells.b.a.c.za.b()) == 0) {
            var8 = "_xlnm.Print_Area";
         } else if (com.aspose.cells.b.a.zv.a(var8, "Print_Titles", true, com.aspose.cells.b.a.c.za.b()) == 0) {
            var8 = "_xlnm.Print_Titles";
         }

         if (var3.a == null) {
            this.a(var1, var8, var5, var4, var3.j(), (String)null, (String)null, var3.getComment());
         } else {
            this.a(var1, var8, var5, var4, var3.j(), var3.a.b, var3.a.a, var3.getComment());
         }
      }
   }

   private void s(zcfx var1) throws Exception {
      if (this.a.b != null && this.a.b.i.i.size() != 0) {
         ArrayList var2 = this.a.b.i.i;

         for(int var3 = 0; var3 < var2.size(); ++var3) {
            int var4 = -1;
            zpz var5 = (zpz)var2.get(var3);
            if (var5.c != null) {
               for(int var6 = 0; var6 < this.b.c.size(); ++var6) {
                  zol var7 = (zol)this.b.c.get(var6);
                  if (var5.c == var7.a) {
                     var4 = var7.c - 1;
                     break;
                  }
               }
            }

            this.a(var1, var5.a, var4, var5.b, false, var5.e, var5.d, (String)null);
         }

      }
   }

   private void a(zcfx var1, String var2, int var3, String var4, boolean var5, String var6, String var7, String var8) throws Exception {
      var1.b("definedName");
      var1.a("name", var2);
      if (var3 != -1) {
         var1.a("localSheetId", zase.y(var3));
      }

      if (var5) {
         var1.a("hidden", "1");
      }

      if (var6 != null) {
         var1.a("publishToServer", var6);
      }

      if (var7 != null) {
         var1.a("workbookParameter", var7);
      }

      if (var8 != null) {
         var1.a("comment", var8);
      }

      var1.a(var4);
      var1.b();
   }
}
